package com.home.livedata

import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        var timeLiveDataViewModel: TimeLiveDataViewModel =
            ViewModelProvider(this).get(TimeLiveDataViewModel::class.java)
        val mutableLiveData = timeLiveDataViewModel.getCurrentSecond()

        mutableLiveData.observe(this, object : Observer<Int> {
            override fun onChanged(t: Int?) {
                findViewById<TextView>(R.id.time_tv).text = "Time:$t"
            }
        })
        runOnUiThread {

            timeLiveDataViewModel.startTiming()
        }
    }
}